﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RebEngine.GameComponents;
using RebEngine.Managers;

namespace RebellionII.GameScreens
{
    public class LoadingScreen : GameScreen
    {
        GameplayScreen gameScreen;
        public LoadingScreen()
            :base()
        {
            TransitionOnTime = TimeSpan.FromSeconds(2.0f);
            TransitionOffTime = TimeSpan.FromSeconds(2.0f);

            ScreenManager.RemoveScreen(this);
        }

        public override void Initialize()
        {
            
        }

        public override void LoadContent()
        {
            base.LoadContent();
            TextureManager.AddTexture("backing");
            TextureManager.AddTexture("starBackground");
            TextureManager.AddTexture("Gui");
            TextureManager.AddTexture("earthcloudmap");
            TextureManager.AddTexture("planet_temperate");
            TextureManager.AddTexture("halo");
            TextureManager.AddTexture("BackingStars");
            TextureManager.AddTexture("Clear");
            TextureManager.AddTexture("Cost");
            TextureManager.AddTexture("Upkeep");

            TextureManager.AddTexture("FleetIcon");
            TextureManager.AddTexture("ConflictIcon");
            TextureManager.AddTexture("DefenceIcon");
            TextureManager.AddTexture("MissionIcon");
            TextureManager.AddTexture("ManufactureIcon");
            TextureManager.AddTexture("PopularSupport");
            TextureManager.AddTexture("ResourceIcon");
            TextureManager.AddTexture("Chat");
            TextureManager.AddTexture("f1img");
            TextureManager.AddTexture("f2img");
            TextureManager.AddTexture("f3img");
            TextureManager.AddTexture("f4img");


            ShaderManager.AddShader("Planet");
            ShaderManager.AddShader("Phong");

            ModelManager.AddModel("plane");
            ModelManager.AddModel("sphere");
            ModelManager.AddModel("octasphere");
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if ((NetClientManager.ReadyToStart) & (gameScreen == null))
            {
                gameScreen = new GameplayScreen(true);
                ScreenManager.AddScreen(gameScreen);
            }
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            Viewport viewport = EngineManager.Device.Viewport;

            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            byte fade = TransitionAlpha;

            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, "Loading...", new Vector2(viewport.Width / 2 - ScreenManager.Font.MeasureString("Loading...").X / 2, 350), Color.White);
            ScreenManager.SpriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
